//
//  ThreeViewController.m
//  xib-zuoye3
//
//  Created by 金隆 on 2017/4/2.
//  Copyright © 2017年 金隆. All rights reserved.
//

#import "ThreeViewController.h"

@interface ThreeViewController ()

@property (weak, nonatomic) IBOutlet UIView *shuzi0;

@property (weak, nonatomic) IBOutlet UIView *chuhao;

@property (weak, nonatomic) IBOutlet UIView *denghao;

@property (weak, nonatomic) IBOutlet UIView *shuzi1;

@property (weak, nonatomic) IBOutlet UIView *shuzi2;

@property (weak, nonatomic) IBOutlet UIView *shuzi3;

@property (weak, nonatomic) IBOutlet UIView *jiahao;

@property (weak, nonatomic) IBOutlet UIView *shuzi4;

@property (weak, nonatomic) IBOutlet UIView *shuzi5;

@property (weak, nonatomic) IBOutlet UIView *shuzi6;

@property (weak, nonatomic) IBOutlet UIView *jianhao;

@property (weak, nonatomic) IBOutlet UIView *shuzi7;

@property (weak, nonatomic) IBOutlet UIView *shuzi8;

@property (weak, nonatomic) IBOutlet UIView *shuzi9;

@property (weak, nonatomic) IBOutlet UIView *chenghao;

@property (weak, nonatomic) IBOutlet UILabel *jieguoLab;

@property (strong, nonatomic) NSString *strOne ;//第一个数字存放的对象

@property (strong, nonatomic) NSString *strTwo; //第二个数字存放的对象

@property (strong, nonatomic) NSString *fuhao; //符号

@property (assign, nonatomic) BOOL isOrNotClick; //是否点击了运算符

@end




@implementation ThreeViewController


- (IBAction)chuhaotui:(id)sender{
    _isOrNotClick = YES;
    _fuhao = @"/";

}

- (IBAction)denghaotui:(id)sender {
    //更加运算符来判断做何种运算
    if ([_fuhao isEqualToString:@"+"]) { //判断fuhao这个对象里面存的值是否为“+”
        float i = _strOne.floatValue; //转为int型数据
        float j = _strTwo.floatValue;
        // %d 表示一个int型的数据   %@表示一个对象（下面有%@）
        self.jieguoLab.text = [NSString stringWithFormat:@"%.6g",i+j];
        
    }
    if ([_fuhao isEqualToString:@"-"]) {
        float i = _strOne.floatValue; //转为int型数据
        float j = _strTwo.floatValue;
        self.jieguoLab.text = [NSString stringWithFormat:@"%.6g",i-j];
    }
    if ([_fuhao isEqualToString:@"*"]) {
        float i = _strOne.floatValue; //转为int型数据
        float j = _strTwo.floatValue;
        self.jieguoLab.text = [NSString stringWithFormat:@"%.6g",i*j];
    }
    if ([_fuhao isEqualToString:@"/"]) {
        float i = _strOne.floatValue; //转为int型数据
        float j = _strTwo.floatValue;
        self.jieguoLab.text = [NSString stringWithFormat:@"%.6g",i/j];
    }
    //运算完后把所有的内容都设置为空值
    _fuhao = @"";
    _strTwo = @"";
    _strOne = @"";
    _isOrNotClick = NO;

}

- (IBAction)shuzi0tui:(id)sender {
    if(_isOrNotClick){
        _strTwo = [NSString stringWithFormat:@"%@0",_strTwo];
        self.jieguoLab.text  = _strTwo;
    }else{
        _strOne = [NSString stringWithFormat:@"%@0",_strOne];
        self.jieguoLab.text  = _strOne;
    }

    
}

- (IBAction)shuzi4tui:(id)sender {
    if(_isOrNotClick){
        _strTwo = [NSString stringWithFormat:@"%@4",_strTwo];
        self.jieguoLab.text  = _strTwo;
    }else{
        _strOne = [NSString stringWithFormat:@"%@4",_strOne];
        self.jieguoLab.text  = _strOne;
    }

    
    
}

- (IBAction)shuzi5tui:(id)sender {
    if(_isOrNotClick){
        _strTwo = [NSString stringWithFormat:@"%@5",_strTwo];
        self.jieguoLab.text  = _strTwo;
    }else{
        _strOne = [NSString stringWithFormat:@"%@5",_strOne];
        self.jieguoLab.text  = _strOne;
    }

}

- (IBAction)shuzi6tui:(id)sender {
    if(_isOrNotClick){
        _strTwo = [NSString stringWithFormat:@"%@6",_strTwo];
        self.jieguoLab.text  = _strTwo;
    }else{
        _strOne = [NSString stringWithFormat:@"%@6",_strOne];
        self.jieguoLab.text  = _strOne;
    }

}

- (IBAction)jianhaotui:(id)sender {
    //点击之后将_isOrNotClick的值设置为yes(默认为no);变点击了符号
    _isOrNotClick = YES;
    _fuhao = @"-";
    
}

- (IBAction)shuzi1tui:(id)sender {
    //首先要判断是否点击了符号（运算符）1点击了用strTwo存起来，没点击用strOne存起来
    if(_isOrNotClick){
        //点击了运算符
        //在字符串后面加个1
        _strTwo = [NSString stringWithFormat:@"%@1",_strTwo];
        //将结果赋值给lab,展示出来
        self.jieguoLab.text  = _strTwo;
    }else{
        _strOne = [NSString stringWithFormat:@"%@1",_strOne];
        self.jieguoLab.text  = _strOne;
    }

    
}

- (IBAction)shuzi2tui:(id)sender {
    if(_isOrNotClick){
        _strTwo = [NSString stringWithFormat:@"%@2",_strTwo];
        self.jieguoLab.text  = _strTwo;
    }else{
        _strOne = [NSString stringWithFormat:@"%@2",_strOne];
        self.jieguoLab.text  = _strOne;
    }

}

- (IBAction)shuzi3tui:(id)sender {
    if(_isOrNotClick){
        _strTwo = [NSString stringWithFormat:@"%@3",_strTwo];
        self.jieguoLab.text  = _strTwo;
    }else{
        _strOne = [NSString stringWithFormat:@"%@3",_strOne];
        self.jieguoLab.text  = _strOne;
    }

}

- (IBAction)jiahaotui:(id)sender {
    _isOrNotClick = YES;
    _fuhao = @"+";
}

- (IBAction)shuzi7tui:(id)sender {
    if(_isOrNotClick){
        _strTwo = [NSString stringWithFormat:@"%@7",_strTwo];
        self.jieguoLab.text  = _strTwo;
    }else{
        _strOne = [NSString stringWithFormat:@"%@7",_strOne];
        self.jieguoLab.text  = _strOne;
    }

}

- (IBAction)shuzi8tui:(id)sender {
    if(_isOrNotClick){
        _strTwo = [NSString stringWithFormat:@"%@8",_strTwo];
        self.jieguoLab.text  = _strTwo;
    }else{
        _strOne = [NSString stringWithFormat:@"%@8",_strOne];
        self.jieguoLab.text  = _strOne;
    }

}

- (IBAction)shuzi9tui:(id)sender {
    if(_isOrNotClick){
        _strTwo = [NSString stringWithFormat:@"%@9",_strTwo];
        self.jieguoLab.text  = _strTwo;
    }else{
        _strOne = [NSString stringWithFormat:@"%@9",_strOne];
        self.jieguoLab.text  = _strOne;
    }

}

- (IBAction)chenghaotui:(id)sender {
    _isOrNotClick = YES;
    _fuhao = @"*";

}





-(UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;

}



- (void)viewDidLoad {
    [super viewDidLoad];
    
    _fuhao = @"";
    _strTwo = @"";
    _strOne = @"";
    _isOrNotClick = NO;
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/


@end
